﻿var multiDictionary = (function () {
    this.table = {};

    this.setItemToTable = function (key, val) {
        if (table.hasOwnProperty(key)) {
            table[key].push(val);
        }
        if (table[key] == undefined) {
            table[key] = [];
            table[key].push(val);
        }
    };
    
    this.getItemFromTable = function (key) {
        if (table.hasOwnProperty(key)) {
            return table[key];
        }
        else {
            return null;
        }
    };

    this.getAllItemsFromTable = function () {
        var objList = [];
        for (var key in table) {
            var obj = table[key];
            for (var prop in obj) {
                if (obj.hasOwnProperty(prop)) {
                    objList.push(obj[prop]);
                }
            }
        }
        return objList;
    };
    
    return {
        setItem: setItemToTable,
        getItem: getItemFromTable,
        getAll:getAllItemsFromTable,
        table: table
    };
})();


multiDictionary.setItem("bobo", { name: "Borkata", msg: "Hello" });
multiDictionary.setItem("bobo", { name: "local", msg: "Hello Too" });
multiDictionary.setItem("bobo", { name: "Borkata", msg: "How are you" });
multiDictionary.setItem("bobo", { name: "Borkata", msg: "How are you" });
multiDictionary.setItem("bobo", { name: "local", msg: "fine tx" });
multiDictionary.setItem("joro", 45);
multiDictionary.setItem("joro", 45);
multiDictionary.setItem("bobo", { name: "local", msg: "Halala" });
multiDictionary.setItem("bobo", { name: "Borkata", msg: "shalalala" });

multiDictionary.getAll();

//multiDictionary.setItem("bobo", 33);
//multiDictionary.setItem("bobo", 33);
//multiDictionary.setItem("bobo", 33);
console.log(multiDictionary);
console.log(multiDictionary.table);
console.log("");
console.log("");
console.log("");
console.log("");
console.log("");
console.log("");
console.log("");
console.log("");
console.log("");
console.log("");
console.log("");
console.log("");























